package org.hive.animation
{
	import fl.motion.Animator;
	import fl.motion.MotionEvent;
	import flash.utils.Timer;
	import flash.events.TimerEvent;
    import flash.events.EventDispatcher;

	import org.hive.events.MotionDelayEvent;

	public class MotionDelay extends EventDispatcher
	{
        /**
        *
        */
		private var __timer:Timer;

        /**
        *
        */
        private var __animator:Animator;
		
        /**
        *
        * @param	delay
        */
		public function MotionDelay( delay:Number )
		{
			__timer = new Timer( delay, 1 );
			__timer.addEventListener( TimerEvent.TIMER_COMPLETE, onDelayComplete, false, 0, true );
		}
		
        /**
        *
        * @param	onCompleteHandler
        * @param	animator
        * @return
        */
		public function start( onCompleteHandler:Function, animator:Animator ):void
		{
			__animator = animator;
            addEventListener( MotionDelayEvent.ON_COMPLETE, onCompleteHandler, false, 0, true );
			__timer.start( );
		}
		
        /**
        *
        * @param	e
        * @return
        */
		private function onDelayComplete( e:TimerEvent ):void
		{
			var event:MotionDelayEvent = new MotionDelayEvent( MotionDelayEvent.ON_COMPLETE, __animator );
			dispatchEvent( event );
		}
	}
}